#include"muil_thread.h"
#include<iostream>
using namespace std;
//启动线程池
threadpool::threadpool(int num)
{
    for(int i=0;i<num;i++)
    {
        works.emplace_back([this]{
            //while不断取任务
            while(true)
            {
                function<void()>task;
                {
                   unique_lock<mutex> lock(task_mutex);//上互斥锁
                   condition.wait(lock,[this]{return !tasks.empty();});//条件锁
                   task= tasks.front();
                   tasks.pop();
                }
                task();
            }
        });
    }
}

//析构函数
threadpool::~threadpool()
{
    for(thread &work: works)
    {
        work.join();
    }
}




